﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Linq;
using Ext.Net;

namespace FastTravel.IntranetWeb
{
	public partial class Dashboard : BasePage
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			if (!ExtNet.IsAjaxRequest)
			{
				XElement document = XElement.Load(Server.MapPath(resDashboard));
				var defaultIcon = document.Attribute("defaultIcon") != null ? document.Attribute("defaultIcon").Value : "";

				var query = from g in document.Elements("group")
							select new
							{
								Title = g.Attribute("title") != null ? g.Attribute("title").Value : "",
								Items = (from i in g.Elements("item")
										 select new
										 {
											 Title = i.Element("title") != null ? i.Element("title").Value : "",
											 Icon = i.Element("item-icon") != null ? i.Element("item-icon").Value : defaultIcon,
											 Accordion = i.Element("accordion-item") != null ? i.Element("accordion-item").Value : "",
											 MenuItem = i.Element("menu-item") != null ? i.Element("menu-item").Value : ""
										 }
									)
							};

				this.storeDashboard.DataSource = query;
				this.storeDashboard.DataBind();
			}
		}
	}
}